﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
//using Microsoft.Practices.EnterpriseLibrary.Data;

namespace DAL
{
    public class PhanloaiDAL:DataService
    {
        #region[Phanloai_GetByAll]
        public DataTable Phanloai_GetByAll()
        {
            using (SqlCommand cmd = new SqlCommand("Phanloai_GetByAll", getConn()))
            {
                cmd.CommandType= CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        #endregion

        #region[Phanloai_GetById]
        public DataTable Phanloai_GetById(string id)
        {
            using (SqlCommand cmd = new SqlCommand("Phanloai_GetById", getConn()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Ma_Phan_loai", id));
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        #endregion

        #region[Phanloai_GetByTop]
        public DataTable Phanloai_GetByTop(string Top, string Where, string Order)
        {
            using (SqlCommand cmd = new SqlCommand("Phanloai_GetByTop", getConn()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Top", Top));
                cmd.Parameters.Add(new SqlParameter("@Where", Where));
                cmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        #endregion

        #region[Phanloai_Insert]
        public void Phanloai_Insert(PhanloaiInfo data)
        {
            using (SqlCommand cmd = new SqlCommand("Phanloai_Insert", getConn()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Ma_phan_loai", data.Ma_Phan_loai));
                cmd.Parameters.Add(new SqlParameter("@Ten_Phan_loai", data.Ten_Phan_loai));
                cmd.ExecuteNonQuery();
            }
            //return true;
        }
        #endregion

        #region[Phanloai_Update]
        public void Phanloai_Update(PhanloaiInfo data)
        {
            using (SqlCommand cmd = new SqlCommand("Phanloai_Update", getConn()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Ma_Phan_loai", data.Ma_Phan_loai));
                cmd.Parameters.Add(new SqlParameter("@Ten_Phan_loai", data.Ten_Phan_loai));
                cmd.ExecuteNonQuery();
            }
            //return true;
        }
        #endregion

        #region[Phanloai_Delete]
        public void Phanloai_Delete(string id)
        {
            using (SqlCommand cmd = new SqlCommand("Phanloai_Delete", getConn()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Ma_Phan_loai", id));
                cmd.ExecuteNonQuery();
            }
            //return true;
        }
        #endregion

    }
}
